package com.creating.mict.action;



import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.creating.mict.common.mess.SMSCaClient;
import com.creating.mict.domain.Patient;
import com.creating.mict.domain.XyjRecord;
import com.creating.mict.service.IMessService;
import com.creating.mict.service.IPatientService;
import com.creating.mict.service.IXyjService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
* @ClassName: XyjAction 
* @Description: 血压计模块ACtion
* @author xuelei
* @date Dec 27, 2012 10:28:55 AM 
*
 */
@SuppressWarnings("serial")
public class MessAction extends ActionSupport {

	@Resource
	private IMessService messService;
	@Resource
	private IPatientService patientService;
	
	/**
	 * 
	* @Title: sendMess 
	* @Description: 发送短信并保存发送记录
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String sendMess() {
		HttpServletRequest request = ServletActionContext.getRequest();
		//或当前登录用户名
		String loginName = (String)request.getSession().getAttribute("loginName");
		
		fcontent = replaceBlank(fcontent);
		
		SMSCaClient caClient = new SMSCaClient();
		caClient.testPost(caClient.sendMessXmlInfo(fphone, fcontent));
		
		boolean boo = messService.saveMessSend(loginName, fphone, fcontent, "", ""); 
		
		if(boo) {
			request.setAttribute("result", "{success:true,message:'发送短信成功!'}");
		} else {
			request.setAttribute("result", "{success:true,message:'发送短信失败!'}");
		}
		return "success";
	}
	
	/**
	 * 
	* @Title: sendMessClient 
	* @Description: 客户端发送短信 
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String sendMessClient() {
		HttpServletRequest request = ServletActionContext.getRequest();
		//或当前登录用户名
		String loginName = (String)request.getSession().getAttribute("loginName");
		
		Patient patient = patientService.queryPatientByKeyWords(fpid);
		fcontent = replaceBlank(fcontent);
		SMSCaClient caClient = new SMSCaClient();
		caClient.testPost(caClient.sendMessXmlInfo(patient.getFphone1(), fcontent));
		
		boolean boo = messService.saveMessSend(loginName, patient.getFphone1(), fcontent, "", ""); //全部查询，包括隐藏信息
		
		request.setAttribute("result", "{success:true,message:'发送短信成功!'}");
		return "success";
	}
	
	/**
	 * 
	* @Title: queryRMessCountToChart 
	* @Description: 根据参数计算接收短信总数目
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	public String queryRMessCountToChart() {
		HttpServletRequest request = ServletActionContext.getRequest();
		//或当前登录用户名
		String loginName = (String)request.getSession().getAttribute("loginName");
		String str = ""; //messService.queryRMessCountToChart(fbtime, fetime, ftjlx, loginName);
		request.setAttribute("result", str);
		return "success";
	}
	
	/**
	 * 
	* @Title: replaceBlank 
	* @Description: 替换回车和空格
	* @param @param str
	* @param @return 
	* @return String    返回类型 
	* @throws
	 */
	private String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
	
	private int limit = 50; //分页结束
	private int start = 0;  //分页起始
	private int total;		//总页数
	
	private String ftjlx;
	
	private String query;
	private String fbtime;
	private String fetime;
	private String fkeywords;
	
	private String fpid;
	private String fcontent;
	private String freceiver;
	private String fphone;
	private String ftype;

	public int getLimit() {
		return limit;
	}



	public void setLimit(int limit) {
		this.limit = limit;
	}



	public int getStart() {
		return start;
	}



	public void setStart(int start) {
		this.start = start;
	}



	public int getTotal() {
		return total;
	}



	public void setTotal(int total) {
		this.total = total;
	}



	public String getQuery() {
		return query;
	}



	public void setQuery(String query) {
		this.query = query;
	}



	public String getFbtime() {
		return fbtime;
	}



	public void setFbtime(String fbtime) {
		this.fbtime = fbtime;
	}



	public String getFetime() {
		return fetime;
	}



	public void setFetime(String fetime) {
		this.fetime = fetime;
	}



	public String getFkeywords() {
		return fkeywords;
	}



	public void setFkeywords(String fkeywords) {
		this.fkeywords = fkeywords;
	}



	public String getFpid() {
		return fpid;
	}



	public void setFpid(String fpid) {
		this.fpid = fpid;
	}



	public String getFcontent() {
		return fcontent;
	}



	public void setFcontent(String fcontent) {
		this.fcontent = fcontent;
	}



	public String getFreceiver() {
		return freceiver;
	}



	public void setFreceiver(String freceiver) {
		this.freceiver = freceiver;
	}



	public String getFphone() {
		return fphone;
	}



	public void setFphone(String fphone) {
		this.fphone = fphone;
	}



	public String getFtype() {
		return ftype;
	}



	public void setFtype(String ftype) {
		this.ftype = ftype;
	}

	public String getFtjlx() {
		return ftjlx;
	}

	public void setFtjlx(String ftjlx) {
		this.ftjlx = ftjlx;
	}
	
	
}
